package com.seo.controller.lightpay;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.seo.pojo.ReturnBody;
import com.seo.service.lightpay.sdk.LightPayAlipayService;
import com.seo.utils.alipay.AlipayConfig;

import lombok.extern.slf4j.Slf4j;

/**
 * 支付宝Controller <br/>
 * 
 * @author shibeilei
 * @version 2017.11.30 12:20
 */
@Slf4j
@Controller
@RequestMapping(value = "/lightpay/")
public class LightPayController {

	@Autowired
	private LightPayAlipayService lightPayAlipayService;

	@RequestMapping(value = "alipayConfigList")
	public String alipayConfigList(@RequestParam Map<String, Object> params, HttpServletRequest request,
			HttpSession session) {
		log.info("获取支付宝配置...");
		ReturnBody rb = ReturnBody.init();
		rb.run(lightPayAlipayService.getAlipayConfigList(params));
		request.setAttribute("page", rb.get("page"));

		return "lightpay/alipay/configList";

	}

	@ResponseBody
	@RequestMapping("/save")
	public ReturnBody save(@RequestBody AlipayConfig ac) {
		return lightPayAlipayService.save(ac, null);
	}

	@ResponseBody
	@RequestMapping("/updateState")
	public ReturnBody updateState(Integer id, String state) {
		return lightPayAlipayService.updateState(id, state);
	}

}
